
<template>


  <div>

    <a-button v-show="ifLogin" type="primary" @click="addThankModal">发布感谢信</a-button>

    <a href="#/sign-in"  v-show="!ifLogin"> 登录之后发布感谢信 </a>

    <a-modal v-model:visible="visible" title="发布感谢信" @ok="handleOk">

      <a-textarea maxlength="256" v-model:value="value" placeholder="请输入内容" :rows="4" />

    </a-modal>

    <a-table :columns="columns" :data-source="thankList">

    </a-table>
  </div>

</template>

<script>

const columns = [
  {
    title:"发布者",
    dataIndex: 'createUserName',
    key: 'createUserName',
  },
  {
    title:"内容",
    dataIndex: 'text',
    key: 'text',
    ellipsis:true
  }
];


import { message } from 'ant-design-vue';

export default ({
  data() {
    return {
      thankList:[],
      visible:false,
      value:"",
      columns,
      ifLogin:false
    }
  },
  beforeCreate() {

    this.$http({
      method: 'get',
      url: 'http://localhost:18082/thank/getall',
      data: {},
      headers:{
        user:localStorage.getItem("user"),
      }
    }).then((e)=>{

      this.thankList=e.data.data;
      console.log("查看当前事项",e);

    })


  },
  mounted() {

    if(localStorage.getItem("user")==null||localStorage.getItem("user")==""){
      this.ifLogin=false;

      console.log("当前没有登录");
    }else{
      this.ifLogin=true;

      console.log("当前已经登录");
    }

  },
  methods: {
    addThankModal(){
      this.visible=true;
    },
    handleOk(){

      this.$http({
        method: 'post',
        url: 'http://localhost:18082/thank/addthank',
        data: {
          text:this.value
        },
        headers:{
          user:localStorage.getItem("user"),
        }
      }).then((e)=>{

        if(e.data.status){

          message.info("发布成功",3);
          this.visible=false;
          this.$http({
            method: 'get',
            url: 'http://localhost:18082/thank/getall',
            data: {},
            headers:{
              user:localStorage.getItem("user"),
            }
          }).then((e)=>{
            this.thankList=e.data.data;
            console.log("查看当前事项",e);
          })


        }else{
          message.error("发布失败",3);
        }

      })

    }
  }
})

</script>

